Respect importModuleSpecifierPreference in sort order between fixes for the same symbol from different files#58597
Merged
andrewbranch merged 4 commits intomicrosoft:mainfrom May 21, 2024
Merged
Conversation
… for the same symbol from different files
andrewbranch
commented
May 20, 2024
| //// isBrowser/**/ | ||
|
|
||
| verify.importFixModuleSpecifiers("", ["./env/browser.js", "#is-browser"]); No newline at end of file | ||
| verify.importFixModuleSpecifiers("", ["#is-browser", "./env/browser.js"]); |
Member
Author
There was a problem hiding this comment.
It always should have been in this order due to number of path segments, but #is-browser was being demoted because it was being checked against package.json dependencies, as I mentioned in the PR description.
jakebailey
approved these changes
May 21, 2024
sheetalkamat
approved these changes
May 21, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #55863
There were two bugs in play:
importModuleSpecifierPreferencewas only being considered in how to generate module specifiers between a given pair of files. But when computing auto-imports, there may be multiple files a missing symbol can be imported from, so the module specifier generation code is called multiple times, and multiple fixes are generated. Those fixes are then sorted, but the sort logic didn’t considerimportModuleSpecifierPreference. In most cases, all the generated fixes either successfully satisfied the preference or didn’t, but it’s possible, as in the bug repro and test case, that e.g. the symbol being imported is available from one file that can only be reached by relative path and another file that can be reached by a non-relativepaths/baseUrlmodule specifier.paths/baseUrl. We were incorrectly checking whether thesepaths/baseUrlspecifiers were package.json dependencies, which would further deprioritize them under relative paths. (Writing this out makes me realize that I need to follow up with a separate test to ensure that package.jsonimportsand self-name imports are not being deprioritized for the same reason.)